﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ANN.FeedForward {
    public class Network : INeuralNet {
        public Network(int inputs, int outputs, int layers, int neurons) {
            InputCount = inputs;
            OutputCount = outputs;
            LayerCount = layers;
            NeuronsPerLayer = neurons;

            Layers = new Layer[LayerCount + 1];

            // Create the first Hidden layer
            Layers[0] = new Layer(NeuronsPerLayer, InputCount);

            // Create the other Hidden layers
            for (int i = 1; i < LayerCount; i++) {
                Layers[i] = new Layer(NeuronsPerLayer, NeuronsPerLayer);
            }

            // Create the Output layer
            Layers[LayerCount] = new Layer(OutputCount, NeuronsPerLayer);

            // Randomize Synapse Weights
            Random random = new Random();

            foreach (Layer layer in Layers) {
                foreach (Neuron neuron in layer.Neurons) {
                    for (int i = 0; i < neuron.Weights.Length; i++) {
                        neuron.Weights[i] = (float)random.NextDouble();
                    }
                }
            }
        }

        public override float[] Calculate(float[] inputs) {
            // Set Outputs
            Outputs = inputs;

            // Iterate through the layers, saving each result in Outputs before using it in the next layer
            for(int i = 0; i < Layers.Length; i++) {
                Outputs = Layers[i].Calculate(Outputs);
            }

            return Outputs;
        }
    }
}
